package nullby.yoga.utils;

import nullby.yoga.R;
import android.app.Dialog;
import android.os.Bundle;
import android.os.Handler;
import android.os.ResultReceiver;
import android.widget.TextView;

public class DownloadReceiver extends ResultReceiver {
	private Dialog mProgressDialog;

	public DownloadReceiver(Handler handler) {
		super(handler);
	}

	public DownloadReceiver(Handler handler, Dialog mProgressDialog) {
		super(handler);
		this.mProgressDialog = mProgressDialog;
	}

	@Override
	protected void onReceiveResult(int resultCode, Bundle resultData) {
		super.onReceiveResult(resultCode, resultData);
		if (resultCode == DownloadService.UPDATE_PROGRESS) {
			int progress = resultData.getInt("progress");
			TextView txt = (TextView) mProgressDialog
					.findViewById(R.id.tvProgress);
			txt.setText(String.valueOf(progress));
			// mProgressDialog.setProgress(progress);
			if (progress == 100) {
				mProgressDialog.dismiss();
			}
		}
	}
}
